//
//  UIButton+Extension.swift
//  新浪微博
//
//  Created by MBP on 16/5/14.
//  Copyright © 2016年 MBP. All rights reserved.
//

import UIKit

extension UIButton {
    convenience init(pn_title title: String?,
           fontSize: CGFloat = 17,
           titleColor: UIColor = UIColor.darkGrayColor(),
           imageName: String? = nil,
           backImageName: String? = nil) {
        
        self.init()
        
        self.setTitle(title, forState: .Normal)
        self.setTitleColor(titleColor, forState: .Normal)
        self.titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
        if let imageName = imageName {
            self.setImage(UIImage(named: imageName), forState: .Normal)
            self.setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        }
        if let backImageName = backImageName {
            self.setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
            self.setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
        }
        
        sizeToFit()
    }
}